Inside Macintosh: QuickTime Components

Previous | Chapter Top | Chapter Contents | Next

Managing Your Media Handler Component

Derived media handlers provide three functions that allow the Movie Toolbox to manage its relationship with the media handler. The Movie Toolbox calls your MediaInitialize function in order to give you an opportunity to prepare to provide access to your media. The Movie Toolbox grants processing time to your handler by calling your MediaIdle function. Your MediaGGetStatus function allows the Movie Toolbox to retrieve status information after calling MediaIdle .

MediaInitialize

The MediaInitialize function allows your derived media handler component to prepare itself for providing access to its media.

pascal ComponentResult MediaInitialize (MediaHandler mh,
                                         GetMovieCompleteParams *gmc);
mh
Identifies the Movie Toolbox's connection to your derived media handler.
gmc
Contains a pointer to a complete movie parameter structure, which is described in "Data Type," . You can obtain information about the current media from this structure. You should copy any values you need to save into your derived media handler's local data area.
Because this data structure is owned by the Movie Toolbox, you do not need to worry about disposing of any of the data in it.

DESCRIPTION

Once the Movie Toolbox has loaded a movie's data from its file, the toolbox calls your derived media handler's MediaInitialize function. If the user is creating a new movie, the Movie Toolbox calls your media handler anyway, even though there may be no media data.

This function gives your media handler an opportunity to get ready to support the Movie Toolbox. As part of these preparations, your derived media handler should report its capabilities to the base media handler by calling the MediaSetHandlerCapabilities function (see MediaSetHandlerCapabilities for more information about this function).

You may choose to examine the data in the movie parameter structure; you may also save values from this structure. If you save references to structures (such as the matte pixel map), do not dispose of the memory associated with these structures. The Movie Toolbox owns these structures.

All derived media handlers should support this function. In addition, if your media handler saves values from the movie parameter structure that may change, be sure to support the corresponding functions that allow the Movie Toolbox to report changes to your media handler. For example, if your handler saves the movie time scale from the movieScale field, you should also support the MediaSetMovieTimeScale function.

If you return an error, the Movie Toolbox disables the track that uses your media. In cases where your media has just been created, the Movie Toolbox immediately disposes of your media.

Note that the Movie Toolbox may call other functions supported by your media handler before it calls your MediaInitialize function. In particular, it may call your MediaGetMediaInfo and MediaPutMediaInfo functions. However, before the Movie Toolbox tries to do anything with the data in your media, it will call your MediaInitialize function. The Movie Toolbox loads the movie's data using functions that are supported by the base media handler--your media handler does not have to support those functions.

RESULT CODES

Any Component Manager result code

MediaIdle

The MediaIdle function allows the Movie Toolbox to provide processing time to your derived media handler during movie playback. Your media handler may use this time to play its media.

pascal ComponentResult MediaIdle (MediaHandler mh,
                                         TimeValue atMediaTime,
                                         long flagsIn, long *flagsOut,
                                         const TimeRecord *movieTime);
mh
Identifies the Movie Toolbox's connection to your derived media handler.
atMediaTime
Specifies the current time, in your media's time base. You can use this time to determine the appropriate media data to work with.
flagsIn
Contains flags that indicate what the Movie Toolbox wants your media handler to do. These flags are applicable only to media handlers that perform their own scheduling.
The following flags are defined--the Movie Toolbox may use none, or it may set one or more flag to 1:
mMustDraw
Indicates that your media handler must play its media at this time. For graphical media, this means that your handler must draw the appropriate media data on the screen. For sound-based media, your handler must play the media's sounds. If this flag is set to 1, the Movie Toolbox has encountered a new sample in your media.
mAtEnd
Indicates that the current time corresponds to the end of the movie.
mPreflightDraw
Indicates that your media handler must not play its media at this time. Your handler may examine the media data and prepare to play it, but you should not draw any graphical data or play any sounds. If this flag is set to 1, your handler must not play its data.
If these flags are set to 0, then your media handler is free to decide whether to play the media data or not.
flagsOut
Contains a pointer to a long integer that your media handler uses to indicate to the Movie Toolbox what the handler did. You must always set the values of these flags appropriately.
The following flags are defined:
mDidDraw
Indicates that your media handler played its media's data with the handlerHasSpatial flag set, then it drew the data. Any time your media handler plays its media's data, you should set this flag to 1 when you return from your MediaIdle function. The Movie Toolbox uses this information when it is displaying a composited movie-- that is, a movie whose image is derived by blending several tracks together. If your media's track is obscured by other, semitransparent tracks, the Movie Toolbox must redraw those other tracks whenever your media's image changes.
mNeedsToDraw
Indicates that your media handler needs to play its data. Typically, you use this flag when the Movie Toolbox calls your MediaIdle function with the mPreflightDraw flag in the flagsIn field set to 1, and you discover that you have data that must be played at the current time. Set this flag to 1 if your handler needs to play its media's data.
movieTime
Contains a pointer to the movie time value corresponding to the atMediaTime parameter. Note that this may differ from the current value returned by the Movie Toolbox's GetMovieTime function.

DESCRIPTION

The Movie Toolbox uses your MediaIdle function to provide processing time to your derived media handler during movie playback. Your media handler is free to use this time in any appropriate manner. For example, if your media handler supports a sound data type, you might prepare to play your media's sounds or actually play them, depending upon the options asserted by the Movie Toolbox. Your media handler is responsible for limiting the amount of processing time it uses.

The Movie Toolbox provides the current time, in your media's time base, in the atMediaTime parameter. You can use this value to obtain the appropriate samples and sample descriptions from your media (using the Movie Toolbox's GetMediaSample function). Your media handler may then work with the sample data and descriptions as appropriate.

If you encounter an error, save the result code. The Movie Toolbox polls you for status information using the MediaGGetStatus function, which is described next.

Your handler should examine the flagsIn parameter each time the Movie Toolbox calls its MediaIdle function. The flags in this parameter indicate the actions that your handler may perform. In addition, when you return from your MediaIdle function, you should report what you did using the flagsOut parameter. You tell the base media handler that you perform your own scheduling by setting the handlerNoScheduler flag to 1 in the flags parameter of the MediaSetHandlerCapabilities function (see MediaSetHandlerCapabilities for more information about this function).

If your media handler changes any of the settings of the movie's graphics port or graphics world, be sure to restore the original settings before you exit. In addition, note that you may be drawing into a black-and-white graphics port. Finally, be aware that the Movie Toolbox also uses this function to obtain data for QuickDraw pictures. Therefore, if your media handler does not use QuickDraw when drawing to the screen, be sure to examine the picSave field in the graphics port so that you can detect when the toolbox wants to save an image. Your media handler is then responsible for performing the appropriate display processing. (For details on QuickDraw pictures, see the chapter "Basic QuickDraw" in Inside Macintosh: Imaging .)

Your derived media handler should support this function if you need to do work during movie playback. If you set the handlerNoIdle flag to 1 in the flags parameter of the MediaSetHandlerCapabilities function, the Movie Toolbox does not call your MediaIdle function.

RESULT CODES

Any Component Manager result code

MediaGGetStatus

The MediaGGetStatus function allows your derived media handler to report error conditions to the Movie Toolbox.

pascal ComponentResult MediaGGetStatus (MediaHandler mh,
                                         ComponentResult *statusErr);
mh
Identifies the Movie Toolbox's connection to your derived media handler.
statusErr
Contains a pointer to a component result field. If you have error information that you would like to report to the Movie Toolbox, place an appropriate result code into the field referred to by this pointer.

DESCRIPTION

The Movie Toolbox calls your MediaGGetStatus function whenever an application calls the toolbox's GetMovieStatus or GetTrackStatus function. This provides your media handler an opportunity to report any difficulties it may be having in playing your media. You should use this mechanism to report any errors you encounter in your MediaIdle function (described in the previous section). You may use any appropriate result code.

Your derived media handler should support this function if you anticipate that you may encounter an error when playing your media. Because these errors may include such conditions as low memory or missing hardware, you should only rarely create a derived media handler that does not support this function. If your media handler does not support this function, the base media handler always sets the returned result code to noErr .

RESULT CODES

Any Component Manager result code


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next